home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / StereoScope-3.2 / monitor.m < prev    next >
Encoding:
Text File  |  1992-04-01  |  2.9 KB  |  102 lines

  1. /*
  2.  * Implement the "suggestion" box, to catch user's comments,
  3.  * and also a simple tracking mechanism, to send a blip of
  4.  * mail from the first-time user.  This is akin to releasing
  5.  * helium balloons with postcards that say "If you find me,
  6.  * send this card back to . . ." -- it should be interesting
  7.  * to the community to track the free flow of software on
  8.  * the ethernet.
  9.  *
  10.  * If you have any concerns about this, please check with me.
  11.  *
  12.  * Michael Hawley
  13.  * mike@media-lab.mit.edu
  14.  */
  15.  
  16. #define _NAME "StereoScope"
  17.  
  18. static char *stripnl(char *s){
  19.     char *p;
  20.     for (p=s;*p;p++) if (*p == '\n' || *p == '\r') *p = '\0';
  21.     return s;
  22. }
  23.  
  24. char *
  25. execstr(s) char *s; {
  26.     FILE *f = popen(s,"r");
  27.     char *p = s;
  28.     *s = '\0';
  29.     if (f){
  30.         while (fgets(p,256,f))
  31.             stripnl(p), p += strlen(p);
  32.         pclose(f);
  33.     }
  34.     return s;
  35. }
  36.  
  37. static void
  38. monitorMail(subj,body,dest) char *subj, *body, *dest; {
  39.     char s[1024], u[256]="whoami", m[256]="hostname", t[4096];
  40.     FILE *f, *popen();
  41.     if (!dest || !*dest) dest = "woo@ornl.gov";
  42.     execstr(u); execstr(m);
  43.     if (!body || !*body){
  44.         body = t;
  45.         sprintf(body, "%s@%s\nIf this mail bounces back to you,\n\
  46. could you please correct the destination path if possible,\n\
  47. and send it to woo@ornl.gov.\n\
  48. We are trying an experiment to track software.\n",u,m);
  49.     }
  50.     sprintf(s,"/usr/ucb/Mail -s \"%s %s@%s\" %s",
  51.     subj && *subj? subj : [NXApp appName], u, m, dest);
  52.     if (f = popen(s,"w"))
  53.         fprintf(f,"%s",body), pclose(f);
  54. }
  55.  
  56. static void
  57. monitor(subj) char *subj; { // send a note at first use.  to track net.
  58.     extern char FirstUsed[];
  59.     if (!*FirstUsed){
  60.         extern long time();
  61.         extern char *ctime();
  62.         long t = time(0);
  63.         if (t < 793414430) // 1995 
  64.         monitorMail(subj,0,0);
  65.         strcpy(FirstUsed,ctime(&t));
  66.         stripnl(FirstUsed);
  67.         [_defaults writeDefaults:_defaults];
  68.     }
  69. }
  70.  
  71. - suggestion:sender {
  72.     char subj[256], w[256] = "whoami";
  73.     char body[4096]="\
  74. John:\n\n\
  75. A handy bit of software!  I use it ALL the time.\n\
  76. Now, I know I should be sending you a T shirt, a card, \n\
  77. maybe a tax deductible surprise to assist in feeding your\n\
  78. hungry family, but all I have are these scrimpy electronic\n\
  79. comments:\n\n\
  80.    <insert accolades & suggestions here>\n\n\
  81.              parsimoniously,\n\
  82.              ";
  83. #define fcall(a)  [s performRemoteMethod:a]
  84. #define call(a,b) [s performRemoteMethod:a with:b length:strlen(b)+1]
  85.     id s = [NXApp appSpeaker];
  86.     NXPortFromName("Mail", NULL); // make sure app is launched
  87.     [s setSendPort:NXPortFromName("MailSendDemo", NULL)];
  88.  
  89.     sprintf(subj,"Comments and suggestions for ``%s'' ",_NAME);
  90.     strcat(subj,[version stringValue]);
  91.     strcat(body,execstr(w)); strcat(body,"\n");
  92.     call("setTo:","woo@ornl.gov");
  93.     call("setSubject:",subj);
  94.     call("setBody:",body);
  95.     
  96.     return self;
  97. }
  98.  
  99. /*
  100.     monitor("StereoScope-1.0-newuser");
  101. */
  102.